﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BBPA.Admin.SYS.ExpressInfo
{
    public partial class Form : FormPage
    {
        BLL.ExpressInfo bll = new BLL.ExpressInfo();
        Model.ExpressInfo model = new Model.ExpressInfo();
        protected void Page_Load(object sender, EventArgs e){}
        /// <summary>
        /// 初始化本页Model
        /// </summary>
        public override void Page_Load_DefaultModel() { model = bll.GetModel(Master.id); }
        /// <summary>
        /// 初始化表单
        /// </summary>
        public override void Form_Default(){}
        /// <summary>
        /// 绑定表单数据【修改时用】
        /// </summary>
        public override void Form_Bind()
        {
            tb_Contacts.Text = model.Contacts;
            tb_Tel.Text = model.Tel;
            tb_Mobile.Text = model.Mobile;
            tb_Address.Text = model.Address;
            tb_Description.Text = model.Description;

            tb_Province.Text = model.Province;
            tb_City.Text = model.City;
        }
        /// <summary>
        /// 提交
        /// </summary>
        public override void Form_Submit()
        {
            string Address = DataTypePlus.requestString(tb_Address.Text);

            if (
                Master.noEmpty(Address, "[详细地址]必须填写") 
                )
            {
                model.ExpressID = DataTypePlus.requestInt(Request.QueryString["ExpressID"]);
                model.Contacts = PageValidate.SqlTextClear(tb_Contacts.Text);
                model.Tel = PageValidate.SqlTextClear(tb_Tel.Text);
                model.Mobile = PageValidate.SqlTextClear(tb_Mobile.Text);
                model.Address = PageValidate.SqlTextClear(tb_Address.Text);
                model.Description =tb_Description.Text;

                model.Province = PageValidate.SqlTextClear(tb_Province.Text);
                model.City = PageValidate.SqlTextClear(tb_City.Text);
                model.Area = "";

                if (Master.formState == EnumHelper.FormState.add) Master.id = bll.Add(model);
                else bll.Update(model);

                BLL.User_Operate_Log.Add(Security.GetCurrentUserID(), EnumHelper.TableName.ExpressInfo, Master.id, Master.formState == EnumHelper.FormState.add ? EnumHelper.OperateType.Add : EnumHelper.OperateType.Update, "");
                Master.SubmitOK();

            }
        }
    }
}